package com.wzdigit.wms.wms.service.tms;

import com.wzdigit.wms.basic.domain.dtos.api.ApiMessage;
import com.wzdigit.wms.wms.domain.TmsDispatchResult;
import com.wzdigit.wms.wms.domain.dto.TmsDispatchResultDto;
import com.wzdigit.wms.wms.mapper.TmsDispatchResultMapper;
import lombok.extern.slf4j.Slf4j;
import net.dreamlu.mica.core.utils.BeanUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.Date;

@Service
@Slf4j
public class TmsDispatchResultService {

    @Autowired
    TmsDispatchResultMapper tmsDispatchResultMapper ;
    /**添加
        * @param dto
        * @return com.wzdigit.wms.wms.domain.dto.ApiMessage
        * @author shuaic
        * @date 2021/8/31 10:38
    */
    @Transactional
    public ApiMessage add(TmsDispatchResultDto dto) {
        try {

            TmsDispatchResult dispatchResult = new TmsDispatchResult();
            BeanUtil.copyNonNull(dto,dispatchResult);
            dispatchResult.setCreateTime(new Date());
            dispatchResult.setCreateUser("system");
            tmsDispatchResultMapper.insert(dispatchResult);
        }catch (Exception e){
            e.printStackTrace();
            log.info(e.getMessage());
            return  new ApiMessage(ApiMessage.RESULT_ERROR,"添加失败，服务端异常");
        }

        return  new ApiMessage(ApiMessage.RESULT_SUCCESS,"成功");

    }
}
